package com.approval.approvalapp.center.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.approval.approvalapp.R;
import com.approval.approvalapp.center.bean.TodayThingBean;
import com.approval.approvalapp.index.HHListActivity;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

public class TodayThingAdapter extends BaseRecycleListAdapter<TodayThingBean> {

    boolean isqs;//是否是全省

    public void setIsqs(boolean isqs) {
        this.isqs = isqs;
        notifyDataSetChanged();
    }

    public TodayThingAdapter(List mList, Context context) {
        super(mList, context);
    }

    @Override
    public int getLayoutId() {
        return R.layout.today_thing_item;
    }

    @Override
    public RecyclerView.ViewHolder createHolder(View view) {

        return new ViewHolder(view);
    }

    @Override
    protected void onBindDefaultViewHolder(RecyclerView.ViewHolder holder, TodayThingBean bean, int position) {
        if (holder instanceof ViewHolder) {
            ((ViewHolder) holder).setData(bean);
        }
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.tv_title)
        TextView tvTitle;
        @Bind(R.id.tv_number)
        TextView tvNumber;
        @Bind(R.id.jian)
        TextView jian;
        @Bind(R.id.root)
        RelativeLayout root;
        @Bind(R.id.colorv)
        View colorv;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }

        public void setData(final TodayThingBean bean) {

            tvTitle.setText(bean.getTitle());
            tvNumber.setText(bean.getNumbers() + "");
            if (bean.getTitle().equals("可网办率") ||
                    bean.getTitle().equals("实际网办率")) {
                jian.setVisibility(View.GONE);
            } else {
                jian.setVisibility(View.VISIBLE);
            }

            if (bean.getTitle().equals("红牌") || bean.getTitle().equals("黄牌")) {
                colorv.setVisibility(View.VISIBLE);
            } else {
                colorv.setVisibility(View.INVISIBLE);
            }

            root.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (bean.getTitle().equals("红牌")) {
                        Intent intent = new Intent();
                        intent.putExtra("type", "true");
                        intent.setClass(context, HHListActivity.class);
                        intent.putExtra("isProvince", isqs);
                        context.startActivity(intent);
                    }
                    if (bean.getTitle().equals("黄牌")) {
                        Intent intent = new Intent();
                        intent.putExtra("type", "false");
                        intent.setClass(context, HHListActivity.class);
                        intent.putExtra("isProvince", isqs);
                        context.startActivity(intent);
                    }
                }
            });
        }
    }
}
